package com.boot2.core;

import com.boot2.core.utils.StringUtils;
import org.springframework.web.servlet.LocaleResolver;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Locale;

/**
* @author zhangweilin
* @date 2019/4/30 20:28
* @Description:  语言国际化,获取类似zh_CN的值
*/
public class HlLocaleResolver implements LocaleResolver {
    @Override
    public Locale resolveLocale(HttpServletRequest request) {
        String lang = request.getHeader("lang");
        if (StringUtils.isEmpty(lang)) {
            lang = request.getParameter("lang");
        }
        Locale locale = Locale.getDefault();
        if (lang != null && lang.length() == 5) {
            String[] split = lang.split("_");
            locale = new Locale(split[0], split[1]);
        }
        return locale;
    }
 
    @Override
    public void setLocale(HttpServletRequest request, HttpServletResponse response, Locale locale) {
    }
}